import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

export default defineConfig({
  plugins: [vue()],
  server: {
    proxy: {
      "/api": {
        target: "http://localhost:8080/ws-socket",
        ws: true,
        changeOrigin: true,
        
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
      "/socket": {
        target: "ws://127.0.0.1:8080/ws-socket", 
        ws: true,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/socket/, ""), 
      },
      // 添加 WebSocket 代理
      "/websocket": {
        target: "http://localhost:8080/ws-socket/info?t=1739016507562", 
        ws: true, 
        changeOrigin: true, 
        rewrite: (path) => {
          console.log(`Original Path: ${path}`);
          const newPath = path.replace(/^\/websocket/, "");
          console.log(`Rewritten Path: ${newPath}`);
          return newPath;
        },
      },
    },
 
  },
});
